home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / src / bbedit-30-dev-kit.hqx / BBEdit 3.0 Extension Dev. Kit / Fat Extensions / EducateQuotes.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-09  |  1.6 KB  |  100 lines

  1. #ifndef powerc
  2. #include <SetupA4.h>
  3. #include <A4Stuff.h>
  4. #endif
  5.  
  6. #include "ExternalInterface.h"
  7.  
  8. static Boolean quote_breaks[256];
  9.  
  10. static void init_quote_breaks(void)
  11. {
  12.     short i;
  13.     
  14.     for (i = 0; i < 256; i++)
  15.         quote_breaks[i] = FALSE;
  16.         
  17.     quote_breaks['\t'] = TRUE;
  18.     quote_breaks['\r'] = TRUE;
  19.     quote_breaks[0x00CA] = TRUE;
  20.     quote_breaks[' '] = TRUE;
  21.     quote_breaks['('] = TRUE;
  22.     quote_breaks['{'] = TRUE;
  23.     quote_breaks['['] = TRUE;
  24.     quote_breaks[0x00D2] = TRUE;
  25.     quote_breaks[0x00D4] = TRUE;
  26. }
  27.  
  28. #ifdef powerc
  29. unsigned long __procinfo = ExtensionUPPInfo;
  30. #endif
  31.  
  32. pascal void main(ExternalCallbackBlock *callbacks, WindowPtr w)
  33. {
  34.     Handle h;
  35.     
  36.     long i, len;
  37.     
  38.     long saved_a4;
  39.  
  40.     Boolean changed = FALSE;
  41.     register unsigned char c;
  42.     register unsigned char *p;
  43.     
  44. #ifndef powerc
  45.     saved_a4 = SetCurrentA4();
  46. #endif
  47.  
  48.     h = CallGetWindowContents(callbacks->GetWindowContents, w);
  49.     len = GetHandleSize(h);
  50.         
  51.     init_quote_breaks();
  52.  
  53. #ifdef DO_PROGRESS
  54.     CallStartProgress(callbacks->StartProgress, "\pConverting Quotes…", len, FALSE);
  55. #endif
  56.     
  57.     p = (unsigned char *)*h;
  58.     for (i = 0; i < len; i++)
  59.     {
  60. #ifdef DO_PROGRESS
  61.         CallDoProgress(callbacks->DoProgress, i);
  62. #endif        
  63.         c = *p;
  64.         
  65.         if ((i == 0) || quote_breaks[p[-1]])
  66.         {
  67.             if (c == '"')
  68.                 c = '“';
  69.             else if (c == '\'')
  70.                 c = '‘';
  71.         }
  72.         else
  73.         {
  74.             if (c == '"')
  75.                 c = '”';
  76.             else if (c == '\'')
  77.                 c = '’';
  78.         }
  79.         
  80.         if (c != *p)
  81.         {
  82.             *p = c;
  83.             changed = TRUE;
  84.         }
  85.         
  86.         p++;
  87.     }
  88.  
  89. #ifdef DO_PROGRESS
  90.     CallDoneProgress(callbacks->DoneProgress);
  91. #endif
  92.  
  93.     if (changed)
  94.         CallContentsChanged(callbacks->ContentsChanged, w);
  95.     
  96. #ifndef powerc
  97.     SetA4(saved_a4);
  98. #endif
  99. }
  100.